Skip to content

fix(streaming): Set segment source if unset#6791

Draft
sentrivana wants to merge 15 commits into
masterfrom
ivana/streaming-integration-tests
Draft

fix(streaming): Set segment source if unset#6791
sentrivana wants to merge 15 commits into
masterfrom
ivana/streaming-integration-tests

Conversation

@sentrivana

@sentrivana sentrivana commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Description

Set segment source if not set.

Also, add streaming versions of tests in tracing/test_integration_tests.py.

Issues

Part of #5395

Reminders

Comment thread tests/tracing/test_integration_tests.py Outdated
Comment thread tests/tracing/test_integration_tests.py

@sentry-warden sentry-warden Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Streaming span payload accessed with wrong key "transaction" instead of attributes["sentry.segment.name"]

In test_continue_trace_span_streaming, the falsy-branch asserts trace1_payload["transaction"] == "hi", but streaming span envelopes use the _to_json() format which has "name", not "transaction". The else-branch of the same test correctly uses trace1_payload["attributes"]["sentry.segment.name"], making the falsy-branch a copy-paste error that will raise KeyError at runtime.

Evidence
  • StreamedSpan._to_json() (traces.py:592) produces a dict with keys "name", "trace_id", "attributes", etc., but no top-level "transaction" key.
  • test_continue_trace_span_streaming uses capture_envelopes, so trace1.items[0].payload.json is the raw _to_json() output.
  • The else-branch of the same test correctly accesses trace1_payload["attributes"]["sentry.segment.name"], confirming the expected format.
  • The non-streaming counterpart test_continue_trace calls trace1.get_transaction_event() which does return a "transaction" key — this is the source of the copy-paste.

Identified by Warden code-review

Comment thread tests/tracing/test_integration_tests.py Outdated
Comment thread tests/tracing/test_integration_tests.py Outdated
Comment thread tests/tracing/test_integration_tests.py Outdated
sentrivana and others added 7 commits July 23, 2026 10:49
- Construct sentry-trace headers manually since StreamedSpan.sampled is
  always True, making it impossible to vary parent_sampled via real spans
- Use context managers for streaming spans so they finish and get sent
- Fix sampling condition to match streaming behavior (uses sample_rate/
  sample_rand, not parent_sampled directly)
- Update span name via span.name instead of scope.transaction
- Fix copy-paste errors in DSC test (wrong transaction name, missing
  URL encoding)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@sentrivana
sentrivana force-pushed the ivana/streaming-integration-tests branch from ac2f342 to d8b7724 Compare July 23, 2026 10:48
@sentrivana
sentrivana changed the base branch from master to ivana/fix-incorrect-sampling-decision July 23, 2026 10:48
@sentrivana
sentrivana force-pushed the ivana/streaming-integration-tests branch from b6e7f84 to 2092b87 Compare July 23, 2026 10:58
@github-actions

github-actions Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Codecov Results 📊

96032 passed | ❌ 1 failed | ⏭️ 6328 skipped | Total: 102361 | Pass Rate: 93.82% | Execution Time: 335m 28s

📊 Comparison with Base Branch

Metric Change
Total Tests 📈 +91
Passed Tests 📈 +102
Failed Tests 📈 +1
Skipped Tests 📉 -12

➕ New Tests (1)

View new tests
  • test_profile_captured
    • File: tests.profiler.test_transaction_profiler
    • Status: ❌ Failing

❌ Failed Tests

test_profile_captured

File: tests.profiler.test_transaction_profiler
Suite: py3.8-common
Error: tests/profiler/test_transaction_profiler.py:290: in test_profile_captured assert len(items["profile"]) == 1 E assert 0 == 1 E + where 0 = len([])

Stack Trace
tests/profiler/test_transaction_profiler.py:290: in test_profile_captured
    assert len(items["profile"]) == 1
E   assert 0 == 1
E    +  where 0 = len([])

✅ Patch coverage is 100.00%. Project has 2511 uncovered lines.


Generated by Codecov Action

Base automatically changed from ivana/fix-incorrect-sampling-decision to master July 23, 2026 14:35
@sentrivana sentrivana changed the title test: Add streaming integration tests fix: Set segment source if unset Jul 23, 2026
@sentrivana sentrivana changed the title fix: Set segment source if unset fix(streaming): Set segment source if unset Jul 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant